package view.UIlayer
{
	import event.CustomEvent;
	
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.SpreadMethod;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.sampler.getInvocationCount;
	
	import vo.GameMode;
	
	public class ButtonViewLayer extends Sprite
	{	
		[Embed(source="assets/images/cxks.png")]
		private var cxks:Class;		
		[Embed(source="assets/images/jia.png")]
		private var jia:Class;		
		[Embed(source="assets/images/jian.png")]
		private var jian:Class;
		[Embed(source="assets/images/kanpai.png")]
		private var kanpai:Class;
		[Embed(source="assets/images/ksfp.png")]
		private var ksfp:Class;
		[Embed(source="assets/images/unjia.png")]
		private var unjia:Class;
		[Embed(source="assets/images/unjian.png")]
		private var unjian:Class;
		[Embed(source="assets/images/unkanpai.png")]
		private var unkanpai:Class;
		[Embed(source="assets/images/zlyz.png")]
		private var zlyz:Class;
		
		private var startBtn:Sprite;
		private var againBtn:Sprite;
		private var restartBtn:Sprite;
		
		private var showBtn:Sprite;
		private var unshowBtn:Sprite;
		
		private var addChip:Sprite;	
		private var subChip:Sprite;
		private var unaddChip:Sprite;
		private var unsubChip:Sprite;
		
		private var gm:GameMode = GameMode.getInstance();
		
		public function ButtonViewLayer()
			
		{
			init();
		}
		
		private function init():void{
			
			//loadingMyswf();
			
			startBtn = new Sprite();
			addChild(startBtn);
			startBtn.addChild( new ksfp() );		
			startBtn.x = 635;
			startBtn.y = 535;			
			startBtn.buttonMode = true;
			startBtn.addEventListener(MouseEvent.CLICK,onClikStartBtn);
			
			againBtn = new Sprite();
			againBtn.addChild(new zlyz() );
			addChild(againBtn);
			againBtn.x = 635;
			againBtn.y = 535;
			againBtn.visible = false;
			againBtn.buttonMode = true;
			againBtn.addEventListener(MouseEvent.CLICK,onClikAgainBtn);
			
			restartBtn = new Sprite();
			restartBtn.addChild( new cxks() );
			addChild(restartBtn);
			restartBtn.x = 635;
			restartBtn.y = 535;
			restartBtn.visible = false;
			restartBtn.buttonMode = true;
			restartBtn.addEventListener(MouseEvent.CLICK,onClikReStartBtn);
			
			showBtn = new Sprite();
			showBtn.addChild(new kanpai() );
			addChild(showBtn);
			showBtn.x = 565;
			showBtn.y = 555;
			showBtn.buttonMode = false;
			showBtn.addEventListener(MouseEvent.CLICK,onClickShowBtn);
			
			unshowBtn = new Sprite();
			unshowBtn.addChild(new unkanpai() );
			addChild(unshowBtn);
			unshowBtn.x = 565;
			unshowBtn.y = 555;
			unshowBtn.visible = true;
			
			unaddChip = new Sprite();
			unaddChip.addChild(new unjia());
			addChild(unaddChip);
			unaddChip.x = 520;
			unaddChip.y = 555;			
			
			unsubChip = new Sprite();
			unsubChip.addChild(new unjian());
			addChild(unsubChip);
			unsubChip.x = 480;
			unsubChip.y = 555;
			
			
			addChip = new Sprite();
			addChip.addChild(new jia());
			addChild(addChip);
			addChip.x = 520;
			addChip.y = 555;
			addChip.buttonMode = true;
			addChip.addEventListener(MouseEvent.CLICK,onClikAddChipBtn);
			
			subChip = new Sprite();
			subChip.addChild( new jian());
			addChild(subChip);
			subChip.x = 480;
			subChip.y = 555;
			
			subChip.buttonMode = true;
			subChip.addEventListener(MouseEvent.CLICK,onClikSubChipBtn);
			
		
			
			
		}	

		public function updateGameEnd():void{
			startBtn.visible = false;
			againBtn.visible = false;
			restartBtn.visible = true;	
			
			showBtn.visible = false;
			unshowBtn.visible = true;
			
			subChip.visible = false
			addChip.visible = false;
			unsubChip.visible = true
			unaddChip.visible = true;
			
		}	
	
		public function updateGameStart2():void{
			startBtn.visible = false;
			againBtn.visible = true;
			restartBtn.visible = false;	
			
			showBtn.visible = true;
			unshowBtn.visible = false;
			
			subChip.visible = true;
			addChip.visible = true;
			unsubChip.visible = false;
			unaddChip.visible = false;
			
		}
		
		public function updateGameStart():void{
			startBtn.visible = true;
			againBtn.visible = false;
			restartBtn.visible = false;	
			
			showBtn.visible = false;
			unshowBtn.visible = true;
			
			subChip.visible = true;
			addChip.visible = true;
			unsubChip.visible = false;
			unaddChip.visible = false;		
		}			
		
		private function onClikStartBtn(event:MouseEvent):void{			
			var ce:CustomEvent = new CustomEvent(CustomEvent.ONCLIK_START,true);
			ce.BTNState = 1;			
			dispatchEvent( ce );
		}
		
		private function onClikAgainBtn(event:MouseEvent):void{			
			var ce:CustomEvent = new CustomEvent(CustomEvent.ONCLIK_START,true);
			ce.BTNState = 2;			
			dispatchEvent( ce );
		}
		private function onClikReStartBtn(event:MouseEvent):void{			
			var ce:CustomEvent = new CustomEvent(CustomEvent.ONCLIK_START,true);
			ce.BTNState = 3;			
			dispatchEvent( ce );
		}
		
		private function onClickShowBtn(event:MouseEvent):void{			
			dispatchEvent(new CustomEvent(CustomEvent.ONCLIK_SHOW,true));
		}
		
		private function onClikAddChipBtn(event:MouseEvent):void{			
			dispatchEvent(new CustomEvent(CustomEvent.ONCLIK_ADD,true));
		}
		
		private function onClikSubChipBtn(event:MouseEvent):void{			
			dispatchEvent(new CustomEvent(CustomEvent.ONCLIK_SUB,true));
		}		
	}
}